package com.jy.bo.common.conf.util;

import java.util.regex.Pattern;

/**
 * @program: binary-option
 * @description
 * @author: frank
 * @create: 2020-09-02 20:56
 **/
public class MobileUtils {

    private static final Pattern MOBILE_PATTERN = Pattern.compile("^[6-9]\\d{9,10}$");

    public static boolean isIndiaMobile(String mobile){
        return MOBILE_PATTERN.matcher(mobile).matches();
    }

    public static String removeExcess(String mobile){

        mobile = mobile.trim();
        if(mobile.startsWith("+") && mobile.length() < 12){
            mobile = mobile.replaceAll("\\+", "");
        }
        if(mobile.startsWith("+91") && mobile.length() > 12){
            mobile = mobile.replaceAll("\\+91", "");
        }
        if(mobile.startsWith("91") && mobile.length() > 11){
            mobile = mobile.replaceFirst("91", "");
        }
        return mobile;
    }

    public static void main(String[] args) {
        System.out.println(removeExcess("+9177654312231"));
    }
}
